package edu.cueb.wmis.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.cueb.wmis.pojo.Orderbill;
import edu.cueb.wmis.pojo.Orderbillitem;
import edu.cueb.wmis.pojo.RespBean;
import edu.cueb.wmis.service.IOrderbillService;
import edu.cueb.wmis.service.IOrderbillitemService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuzizhuo
 * @since 2021-04-19
 */
@RestController
@RequestMapping("/orderbill")
public class OrderbillController {

    @Autowired
    private IOrderbillService orderbillService;

    private IOrderbillitemService orderbillitemService;
    @ApiOperation("点击选择物品生成预选单")
    @PostMapping("/out")
    public RespBean addOrderBill(@RequestBody Orderbill orderbill){
        if(orderbillService.addOrderBill(orderbill)){
            return RespBean.success("添加预选单成功");
        }else{
            return RespBean.error("失败");
        }
    }
    @ApiOperation("库管员查询预选概单")
    @GetMapping("/")
    public RespBean getOrderBill(){
        List<Orderbill> obList = orderbillService.list();

        if(obList != null){
            return RespBean.success("成功",obList);
        }else{
            return RespBean.error("失败");
        }
    }

//    @ApiOperation("库管员点击某一项概单")
//    @GetMapping("/{obId}")
//    public RespBean getOrderbillitems(@PathVariable Integer obId){
//        return orderbillService.getOrderItems(obId);
//    }

    @ApiOperation("库管员点击某一项概单")
    @GetMapping("/{billNumber}")
    public RespBean getOrderbillitems(@PathVariable String billNumber){
        return orderbillService.getOrderItemsByBillNumber(billNumber);
    }

    @ApiOperation("查询所有未审核的预选单")
    @GetMapping("/stateIs0")
    public List<Orderbill> getBillsStateIsZero(){
        return orderbillService.list(new QueryWrapper<Orderbill>().eq("state",0));
    }

    @ApiOperation("查询所有已经审核的预选单")
    @GetMapping("/stateIs1")
    public List<Orderbill> getBillsStateIsOne(){
        return orderbillService.list(new QueryWrapper<Orderbill>().eq("state",1));
    }
}
